<script>
	var CurrentSelection;
	var CurrentUnit;
	
	function UpdateHeader(val){
		var SpacingRowStype = document.getElementById('SpacingRow').style;
		if (val == 1){		//Microstrip
			SpacingRowStype.display = 'none';
			
			if (CurrentUnit == 0)
				document.getElementById("ResultHeader").innerHTML = 
						"<tr><td width='20%'>Impedance<br>Zo (Ohms)</td>"+
						"<td width='20%'>Prop.delay<br>Tpd (ps/cm)</td>"+
						"<td width='20%'>Inductance<br>L (nH/cm)</td>"+
						"<td width='20%'>Capacitance<br>C (pF/cm)</td>"+
						"<td width='20%'>Resistance<br>Rdc (mOhm/cm)</td>"+
						"</tr>";
			else
				document.getElementById("ResultHeader").innerHTML = 
						"<tr><td width='20%'>Impedance<br>Zo (Ohms)</td>"+
						"<td width='20%'>Prop.delay<br>Tpd (ps/inch)</td>"+
						"<td width='20%'>Inductance<br>L (nH/inch)</td>"+
						"<td width='20%'>Capacitance<br>C (pF/inch)</td>"+
						"<td width='20%'>Resistance<br>Rdc (mOhm/inch)</td>"+
						"</tr>";
		}
		if (val == 2){	//Stripline
			SpacingRowStype.display = 'none';
			if (CurrentUnit == 0)
				document.getElementById("ResultHeader").innerHTML = 
						"<tr><td width='20%'>Impedance<br>Zo (Ohms)</td>"+
						"<td width='20%'>Prop.delay<br>Tpd (ps/cm)</td>"+
						"<td width='20%'>Inductance<br>L (nH/cm)</td>"+
						"<td width='20%'>Capacitance<br>C (pF/cm)</td>"+
						"<td width='20%'>Resistance<br>Rdc (mOhm/cm)</td>"+
						"</tr>";
			else
				document.getElementById("ResultHeader").innerHTML = 
						"<tr><td width='20%'>Impedance<br>Zo (Ohms)</td>"+
						"<td width='20%'>Prop.delay<br>Tpd (ps/inch)</td>"+
						"<td width='20%'>Inductance<br>L (nH/inch)</td>"+
						"<td width='20%'>Capacitance<br>C (pF/inch)</td>"+
						"<td width='20%'>Resistance<br>Rdc (mOhm/inch)</td>"+
						"</tr>";
		}
		if (val == 3){	//Differential Microstrip
			SpacingRowStype.display = 'table-row';
			document.getElementById("ResultHeader").innerHTML = "<tr><td width='50%'> Differential Ohms</td><td width='50%'>Single ended Ohms</td></tr>";
		}
		if (val == 4){	//Differential Stripline
			SpacingRowStype.display = 'table-row';
			document.getElementById("ResultHeader").innerHTML = "<tr><td width='50%'> Differential Ohms</td><td width='50%'>Single ended Ohms</td></tr>";
		}
	
	}
	
	function SelectNew(val){
		CurrentSelection = val;
		
		UpdateHeader(val);
		
		RefreshGFX(val);
		calcul();	//Recalculate
	}
	
	function UnitChanged(unit){
		var W = parseFloat(document.getElementById("valW").value);
		var H = parseFloat(document.getElementById("valH").value);
		var T = parseFloat(document.getElementById("valT").value);
		var S = parseFloat(document.getElementById("valS").value);
		CurrentUnit = unit;
		UpdateHeader(CurrentSelection);
		if (unit == 0) {		//unit changed to metric
			document.getElementById("unit1").innerHTML = "mm";
			document.getElementById("unit2").innerHTML = "mm";
			document.getElementById("unit3").innerHTML = "mm";
			document.getElementById("unit4").innerHTML = "mm";
			W = W * 0.0254 ;
			H = H * 0.0254;
			T = T * 0.0254;
			S = S * 0.0254;
		}
		else {
			document.getElementById("unit1").innerHTML = "mil";
			document.getElementById("unit2").innerHTML = "mil";
			document.getElementById("unit3").innerHTML = "mil";
			document.getElementById("unit4").innerHTML = "mil";
			W = W / 0.0254;
			H = H / 0.0254;
			T = T / 0.0254;
			S = S / 0.0254;
		}
		document.getElementById("valW").value = W;
		document.getElementById("valH").value = H;
		document.getElementById("valT").value = T;
		document.getElementById("valS").value = S;	
		
		calcul();
	}
	
	var valBtn = function(btn) {
		for (var i=btn.length-1; i > -1; i--) {
			if (btn[i].selected) return btn[i].value;
		}
		return null;
	}
  
	function calcul(){
    var W = parseFloat(document.getElementById("valW").value);
		var H = parseFloat(document.getElementById("valH").value);
		var S = parseFloat(document.getElementById("valS").value);
    var ER = parseFloat(document.getElementById("valER").value);
		var T = parseFloat(document.getElementById("valT").value);
		
		if (CurrentSelection == 1){
			var Z0 = (87 / Math.sqrt(ER + 1.41)) * Math.log(5.98 * H / (0.8*W + T));	
			var Tpd = 10/3 * Math.sqrt(0.475 * ER + 0.67); //ps/unit
		}
		if (CurrentSelection == 2){
			var Z0 = (60 / Math.sqrt(ER)) * Math.log(1.9 * (2*H+T) / (0.8*W + T));		
			var Tpd = 10/3 * Math.sqrt(0.475 * ER + 0.67); //ps/unit
		}
		if (CurrentSelection == 3){
			var Z0 = (87 / Math.sqrt(ER + 1.41)) * Math.log(5.98 * H / (0.8*W + T));
			var Zd = 2 * Z0 * (1 - 0.48*Math.exp(-0.96 * S / H));
		}
		if (CurrentSelection == 4){
			var Z0 = (60 / Math.sqrt(ER)) * Math.log(1.9 * (2*H+T) / (0.8*W + T));
			var Zd = 2 * Z0 * (1 - 0.347*Math.exp(-2.9 * S / (2*H+T)));
		}	
		
		if ((CurrentSelection == 1) || (CurrentSelection == 2)){	
			var L = Tpd * Z0 / 1000; //nH / unit
			var C = Tpd / Z0; //pF / unit
			var ro_copper = 17.2; //(nOhm*m) //Annealed copper
			var Rdc = ro_copper / 1000 / (W*T); //resistance in mOhms/mm
			
			Z0 = Z0.toFixed(3);	
			if (CurrentUnit == 0){
				Tpd = (Tpd*10).toFixed(3);	
				L = (L*10).toFixed(3);	
				C = (C*10).toFixed(3);	
				Rdc = (Rdc*10).toFixed(3);	
			}
			else {
				Tpd = (Tpd / 0.254).toFixed(3);	
				L = (L / 0.254).toFixed(3);	
				C = (C / 0.254).toFixed(3);	
				Rdc = (Rdc / 0.254 / 0.0254 / 0.0254).toFixed(3);		
			}			
			document.getElementById("answer").innerHTML = 
					"<tr><td width='20%'>" + Z0 +
					"</td><td width='20%'>" + Tpd + 
					"</td><td width='20%'>" + L + 
					"</td><td width='20%'>" + C +  
					"</td><td width='20%'>" + Rdc + 
					"</td></tr>";
		}
		
		if ((CurrentSelection == 3) || (CurrentSelection == 4)){
			Z0 = Z0.toFixed(3);
			Zd = Zd.toFixed(3);
			document.getElementById("answer").innerHTML = "<tr><td width='50%'>" + Zd + "</td><td width='50%'>" + Z0 + "</td></tr>";
		}
	}
  </script>
  <script>
   function init() {
			CurrentSelection = 1;
			CurrentUnit = 0;
			SelectNew(1);
			RefreshGFX(1);
			
			var canvas = document.getElementById("canvas1");
      var ctx = canvas.getContext("2d");
			DrawMicrostripIcon(ctx);
			
			var canvas = document.getElementById("canvas2");
      var ctx = canvas.getContext("2d");
			DrawStriplineIcon(ctx);
			
			var canvas = document.getElementById("canvas3");
      var ctx = canvas.getContext("2d");
			DrawDiffMicrostripIcon(ctx);
			
			var canvas = document.getElementById("canvas4");
      var ctx = canvas.getContext("2d");
			DrawDiffStriplineIcon(ctx);
			
			
    }
		function RefreshGFX(gfx){
			var canvas = document.getElementById("canvasGFX");
      var ctx = canvas.getContext("2d");
			if (gfx == 1){
				canvas.height = 84;
				DrawMicrostrip(ctx);
			}
			if (gfx == 2){
				canvas.height = 110;
				DrawStripline(ctx);
			}
			if (gfx == 3){
				canvas.height = 84;
				DrawDiffMicrostrip(ctx);
			}
			if (gfx == 4){
				canvas.height = 110;
				DrawDiffStripline(ctx);
			}	
		}

    function DrawMicrostrip(ctx) {

      // layer1/Path
      ctx.save();
      ctx.beginPath();
      ctx.moveTo(179.8, 74.3);
      ctx.lineTo(0.5, 74.3);
      ctx.lineTo(0.5, 32.4);
      ctx.lineTo(179.8, 32.4);
      ctx.lineTo(179.8, 74.3);
      ctx.closePath();
      ctx.fillStyle = "rgb(140, 198, 62)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(109.1, 32.4);
      ctx.lineTo(72.3, 32.4);
      ctx.lineTo(72.3, 24.1);
      ctx.lineTo(109.1, 24.1);
      ctx.lineTo(109.1, 32.4);
      ctx.closePath();
      ctx.fillStyle = "rgb(247, 147, 29)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(179.8, 82.7);
      ctx.lineTo(0.5, 82.7);
      ctx.lineTo(0.5, 74.3);
      ctx.lineTo(179.8, 74.3);
      ctx.lineTo(179.8, 82.7);
      ctx.closePath();
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(71.7, 24.1);
      ctx.lineTo(71.7, 10.1);
      ctx.lineWidth = 0.5;
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(109.6, 24.1);
      ctx.lineTo(109.6, 10.1);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(71.7, 13.6);
      ctx.lineTo(109.6, 13.6);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(71.7, 13.6);
      ctx.lineTo(75.4, 15.5);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(71.7, 13.6);
      ctx.lineTo(75.4, 11.6);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(109.6, 13.5);
      ctx.lineTo(105.9, 11.6);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(109.6, 13.5);
      ctx.lineTo(105.9, 15.5);
      ctx.stroke();

      // layer1/W
      ctx.font = "12.0px 'Arial'";
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 83.3, 10.3);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("W", 0, 0);
      ctx.restore();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.5, 17.1);
      ctx.lineTo(53.5, 74.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.5, 74.3);
      ctx.lineTo(55.1, 70.1);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.5, 74.3);
      ctx.lineTo(51.7, 70.2);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.4, 32.4);
      ctx.lineTo(51.8, 36.7);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.4, 32.4);
      ctx.lineTo(55.2, 36.6);
      ctx.stroke();

      // layer1/H
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 56.7, 58.7);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("H", 0, 0);
      ctx.restore();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.5, 24.1);
      ctx.lineTo(55.1, 19.9);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.5, 24.1);
      ctx.lineTo(51.7, 20.0);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(71.2, 24.1);
      ctx.lineTo(51.3, 24.1);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(72.3, 32.4);
      ctx.lineTo(51.8, 32.4);
      ctx.stroke();

      // layer1/T
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 41.3, 30.9);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("T", 0, 0);
      ctx.restore();
      ctx.restore();
    }
    function DrawStripline(ctx) {

      // layer1/Path
      ctx.save();
      ctx.beginPath();
      ctx.moveTo(179.8, 101.1);
      ctx.lineTo(0.5, 101.1);
      ctx.lineTo(0.5, 8.9);
      ctx.lineTo(179.8, 8.9);
      ctx.lineTo(179.8, 101.1);
      ctx.closePath();
      ctx.fillStyle = "rgb(140, 198, 62)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(109.1, 59.2);
      ctx.lineTo(72.3, 59.2);
      ctx.lineTo(72.3, 50.8);
      ctx.lineTo(109.1, 50.8);
      ctx.lineTo(109.1, 59.2);
      ctx.closePath();
      ctx.fillStyle = "rgb(247, 147, 29)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(179.8, 109.5);
      ctx.lineTo(0.5, 109.5);
      ctx.lineTo(0.5, 101.1);
      ctx.lineTo(179.8, 101.1);
      ctx.lineTo(179.8, 109.5);
      ctx.closePath();
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(71.7, 50.8);
      ctx.lineTo(71.7, 36.8);
      ctx.lineWidth = 0.5;
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(109.6, 50.8);
      ctx.lineTo(109.6, 36.8);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(71.7, 40.3);
      ctx.lineTo(109.6, 40.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(71.7, 40.3);
      ctx.lineTo(75.4, 42.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(71.7, 40.3);
      ctx.lineTo(75.4, 38.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(109.6, 40.3);
      ctx.lineTo(105.9, 38.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(109.6, 40.3);
      ctx.lineTo(105.9, 42.3);
      ctx.stroke();

      // layer1/W
      ctx.font = "12.0px 'Arial'";
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 83.3, 37.0);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("W", 0, 0);
      ctx.restore();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.5, 50.8);
      ctx.lineTo(53.5, 101.1);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.5, 101.1);
      ctx.lineTo(55.1, 96.8);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.5, 101.1);
      ctx.lineTo(51.7, 96.9);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.4, 59.2);
      ctx.lineTo(51.8, 63.4);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.4, 59.2);
      ctx.lineTo(55.2, 63.3);
      ctx.stroke();

      // layer1/H
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 56.7, 85.4);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("H", 0, 0);
      ctx.restore();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(179.8, 8.9);
      ctx.lineTo(0.5, 8.9);
      ctx.lineTo(0.5, 0.5);
      ctx.lineTo(179.8, 0.5);
      ctx.lineTo(179.8, 8.9);
      ctx.closePath();
      ctx.fill();
      ctx.lineWidth = 1.0;
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.5, 8.9);
      ctx.lineTo(53.5, 51.0);
      ctx.lineWidth = 0.5;
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.5, 50.8);
      ctx.lineTo(55.1, 46.6);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.5, 50.8);
      ctx.lineTo(51.7, 46.7);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.5, 8.9);
      ctx.lineTo(51.9, 13.1);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(53.5, 8.9);
      ctx.lineTo(55.3, 13.0);
      ctx.stroke();

      // layer1/H
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 56.8, 35.1);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("H", 0, 0);
      ctx.restore();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(71.2, 50.8);
      ctx.lineTo(51.3, 50.8);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(72.3, 59.2);
      ctx.lineTo(51.8, 59.2);
      ctx.stroke();

      // layer1/T
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 41.3, 59.2);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("T", 0, 0);
      ctx.restore();
      ctx.restore();
    }
    function DrawDiffMicrostrip(ctx) {

      // layer1/Path
      ctx.save();
      ctx.beginPath();
      ctx.moveTo(70.1, 32.4);
      ctx.lineTo(33.3, 32.4);
      ctx.lineTo(33.3, 24.1);
      ctx.lineTo(70.1, 24.1);
      ctx.lineTo(70.1, 32.4);
      ctx.closePath();
      ctx.fillStyle = "rgb(247, 147, 29)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(179.8, 74.3);
      ctx.lineTo(0.5, 74.3);
      ctx.lineTo(0.5, 32.4);
      ctx.lineTo(179.8, 32.4);
      ctx.lineTo(179.8, 74.3);
      ctx.closePath();
      ctx.fillStyle = "rgb(140, 198, 62)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(143.7, 32.4);
      ctx.lineTo(106.9, 32.4);
      ctx.lineTo(106.9, 24.1);
      ctx.lineTo(143.7, 24.1);
      ctx.lineTo(143.7, 32.4);
      ctx.closePath();
      ctx.fillStyle = "rgb(247, 147, 29)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(179.8, 82.7);
      ctx.lineTo(0.5, 82.7);
      ctx.lineTo(0.5, 74.3);
      ctx.lineTo(179.8, 74.3);
      ctx.lineTo(179.8, 82.7);
      ctx.closePath();
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(32.7, 24.1);
      ctx.lineTo(32.7, 10.1);
      ctx.lineWidth = 0.5;
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(70.6, 24.1);
      ctx.lineTo(70.6, 10.1);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(106.4, 24.1);
      ctx.lineTo(106.4, 10.1);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(144.3, 24.1);
      ctx.lineTo(144.3, 10.1);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(32.7, 13.6);
      ctx.lineTo(70.6, 13.6);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(106.4, 13.6);
      ctx.lineTo(144.3, 13.6);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(32.7, 13.6);
      ctx.lineTo(36.4, 15.5);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(32.7, 13.6);
      ctx.lineTo(36.4, 11.6);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(106.4, 13.5);
      ctx.lineTo(110.0, 15.5);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(106.4, 13.5);
      ctx.lineTo(110.0, 11.6);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(70.6, 13.5);
      ctx.lineTo(66.9, 11.6);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(70.6, 13.5);
      ctx.lineTo(66.9, 15.5);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(144.3, 13.5);
      ctx.lineTo(140.6, 11.6);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(144.3, 13.5);
      ctx.lineTo(140.6, 15.5);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(70.6, 19.3);
      ctx.lineTo(106.4, 19.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(70.6, 19.2);
      ctx.lineTo(74.2, 21.2);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(70.6, 19.2);
      ctx.lineTo(74.2, 17.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(106.4, 19.2);
      ctx.lineTo(102.7, 17.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(106.4, 19.2);
      ctx.lineTo(102.7, 21.2);
      ctx.stroke();

      // layer1/W
      ctx.font = "12.0px 'Arial'";
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 44.3, 10.3);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("W", 0, 0);
      ctx.restore();

      // layer1/W
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 119.9, 10.3);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("W", 0, 0);
      ctx.restore();

      // layer1/S
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 82.9, 16.4);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("S", 0, 0);
      ctx.restore();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(43.5, 32.4);
      ctx.lineTo(43.5, 74.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(43.5, 74.3);
      ctx.lineTo(45.1, 70.1);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(43.5, 74.3);
      ctx.lineTo(41.7, 70.2);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(43.4, 32.4);
      ctx.lineTo(41.8, 36.7);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(43.4, 32.4);
      ctx.lineTo(45.2, 36.6);
      ctx.stroke();

      // layer1/H
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 46.7, 58.7);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("H", 0, 0);
      ctx.restore();
      ctx.restore();
    }
		function DrawDiffStripline(ctx) {
      // layer1/Path
      ctx.save();
      ctx.beginPath();
      ctx.moveTo(179.8, 101.1);
      ctx.lineTo(0.5, 101.1);
      ctx.lineTo(0.5, 8.9);
      ctx.lineTo(179.8, 8.9);
      ctx.lineTo(179.8, 101.1);
      ctx.closePath();
      ctx.fillStyle = "rgb(140, 198, 62)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(70.1, 59.2);
      ctx.lineTo(33.3, 59.2);
      ctx.lineTo(33.3, 50.8);
      ctx.lineTo(70.1, 50.8);
      ctx.lineTo(70.1, 59.2);
      ctx.closePath();
      ctx.fillStyle = "rgb(247, 147, 29)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(143.7, 59.2);
      ctx.lineTo(106.9, 59.2);
      ctx.lineTo(106.9, 50.8);
      ctx.lineTo(143.7, 50.8);
      ctx.lineTo(143.7, 59.2);
      ctx.closePath();
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(179.8, 109.5);
      ctx.lineTo(0.5, 109.5);
      ctx.lineTo(0.5, 101.1);
      ctx.lineTo(179.8, 101.1);
      ctx.lineTo(179.8, 109.5);
      ctx.closePath();
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(32.7, 50.8);
      ctx.lineTo(32.7, 36.8);
      ctx.lineWidth = 0.5;
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(70.6, 50.8);
      ctx.lineTo(70.6, 36.8);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(106.4, 50.8);
      ctx.lineTo(106.4, 36.8);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(144.3, 50.8);
      ctx.lineTo(144.3, 36.8);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(32.7, 40.3);
      ctx.lineTo(70.6, 40.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(106.4, 40.3);
      ctx.lineTo(144.3, 40.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(32.7, 40.3);
      ctx.lineTo(36.4, 42.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(32.7, 40.3);
      ctx.lineTo(36.4, 38.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(106.4, 40.3);
      ctx.lineTo(110.0, 42.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(106.4, 40.3);
      ctx.lineTo(110.0, 38.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(70.6, 40.3);
      ctx.lineTo(66.9, 38.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(70.6, 40.3);
      ctx.lineTo(66.9, 42.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(144.3, 40.3);
      ctx.lineTo(140.6, 38.3);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(144.3, 40.3);
      ctx.lineTo(140.6, 42.2);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(70.6, 46.0);
      ctx.lineTo(106.4, 46.0);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(70.6, 46.0);
      ctx.lineTo(74.2, 48.0);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(70.6, 46.0);
      ctx.lineTo(74.2, 44.0);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(106.4, 46.0);
      ctx.lineTo(102.7, 44.0);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(106.4, 46.0);
      ctx.lineTo(102.7, 48.0);
      ctx.stroke();

      // layer1/W
      ctx.font = "12.0px 'Arial'";
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 44.3, 37.0);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("W", 0, 0);
      ctx.restore();

      // layer1/W
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 119.9, 37.0);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("W", 0, 0);
      ctx.restore();

      // layer1/S
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 82.9, 43.2);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("S", 0, 0);
      ctx.restore();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(14.5, 50.8);
      ctx.lineTo(14.5, 101.1);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(14.5, 101.1);
      ctx.lineTo(16.1, 96.8);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(14.5, 101.1);
      ctx.lineTo(12.7, 96.9);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(14.4, 59.2);
      ctx.lineTo(12.8, 63.4);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(14.4, 59.2);
      ctx.lineTo(16.2, 63.3);
      ctx.stroke();

      // layer1/H
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 17.7, 85.4);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("H", 0, 0);
      ctx.restore();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(179.8, 8.9);
      ctx.lineTo(0.5, 8.9);
      ctx.lineTo(0.5, 0.5);
      ctx.lineTo(179.8, 0.5);
      ctx.lineTo(179.8, 8.9);
      ctx.closePath();
      ctx.fill();
      ctx.lineWidth = 1.0;
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(14.5, 8.9);
      ctx.lineTo(14.5, 51.0);
      ctx.lineWidth = 0.5;
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(14.5, 50.8);
      ctx.lineTo(16.1, 46.6);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(14.5, 50.8);
      ctx.lineTo(12.7, 46.7);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(14.5, 8.9);
      ctx.lineTo(12.9, 13.1);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(14.5, 8.9);
      ctx.lineTo(16.3, 13.0);
      ctx.stroke();

      // layer1/H
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 17.8, 35.1);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("H", 0, 0);
      ctx.restore();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(32.2, 50.8);
      ctx.lineTo(12.3, 50.8);
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(33.3, 59.2);
      ctx.lineTo(12.8, 59.2);
      ctx.stroke();

      // layer1/T
      ctx.save();
      ctx.transform(0.877, 0.000, 0.000, 1.000, 2.3, 59.2);
      ctx.fillStyle = "rgb(0, 0, 0)";
      ctx.fillText("T", 0, 0);
      ctx.restore();
      ctx.restore();
    }
    
		function DrawMicrostripIcon(ctx){
      // layer1/Path
      ctx.save();
      ctx.beginPath();
      ctx.moveTo(80.5, 22.9);
      ctx.lineTo(0.5, 22.9);
      ctx.lineTo(0.5, 4.2);
      ctx.lineTo(80.5, 4.2);
      ctx.lineTo(80.5, 22.9);
      ctx.closePath();
      ctx.fillStyle = "rgb(140, 198, 62)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(48.9, 4.2);
      ctx.lineTo(32.5, 4.2);
      ctx.lineTo(32.5, 0.5);
      ctx.lineTo(48.9, 0.5);
      ctx.lineTo(48.9, 4.2);
      ctx.closePath();
      ctx.fillStyle = "rgb(247, 147, 29)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(80.5, 26.7);
      ctx.lineTo(0.5, 26.7);
      ctx.lineTo(0.5, 22.9);
      ctx.lineTo(80.5, 22.9);
      ctx.lineTo(80.5, 26.7);
      ctx.closePath();
      ctx.fill();
      ctx.stroke();
      ctx.restore();
    }
		function DrawStriplineIcon(ctx){
			// layer1/Path
      ctx.save();
      ctx.beginPath();
      ctx.moveTo(80.5, 26.7);
      ctx.lineTo(0.5, 26.7);
      ctx.lineTo(0.5, 4.2);
      ctx.lineTo(80.5, 4.2);
      ctx.lineTo(80.5, 26.7);
      ctx.closePath();
      ctx.fillStyle = "rgb(140, 198, 62)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(48.0, 15.5);
      ctx.lineTo(31.6, 15.5);
      ctx.lineTo(31.6, 11.7);
      ctx.lineTo(48.0, 11.7);
      ctx.lineTo(48.0, 15.5);
      ctx.closePath();
      ctx.fillStyle = "rgb(247, 147, 29)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(80.5, 26.7);
      ctx.lineTo(0.5, 26.7);
      ctx.lineTo(0.5, 22.9);
      ctx.lineTo(80.5, 22.9);
      ctx.lineTo(80.5, 26.7);
      ctx.closePath();
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(80.5, 4.2);
      ctx.lineTo(0.5, 4.2);
      ctx.lineTo(0.5, 0.5);
      ctx.lineTo(80.5, 0.5);
      ctx.lineTo(80.5, 4.2);
      ctx.closePath();
      ctx.fill();
      ctx.stroke();
      ctx.restore();
    }
		function DrawDiffMicrostripIcon(ctx){
			// layer1/Path
      ctx.save();
      ctx.beginPath();
      ctx.moveTo(31.5, 4.2);
      ctx.lineTo(15.1, 4.2);
      ctx.lineTo(15.1, 0.5);
      ctx.lineTo(31.5, 0.5);
      ctx.lineTo(31.5, 4.2);
      ctx.closePath();
      ctx.fillStyle = "rgb(247, 147, 29)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(80.5, 22.9);
      ctx.lineTo(0.5, 22.9);
      ctx.lineTo(0.5, 4.2);
      ctx.lineTo(80.5, 4.2);
      ctx.lineTo(80.5, 22.9);
      ctx.closePath();
      ctx.fillStyle = "rgb(140, 198, 62)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(64.4, 4.2);
      ctx.lineTo(48.0, 4.2);
      ctx.lineTo(48.0, 0.5);
      ctx.lineTo(64.4, 0.5);
      ctx.lineTo(64.4, 4.2);
      ctx.closePath();
      ctx.fillStyle = "rgb(247, 147, 29)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(80.5, 26.7);
      ctx.lineTo(0.5, 26.7);
      ctx.lineTo(0.5, 22.9);
      ctx.lineTo(80.5, 22.9);
      ctx.lineTo(80.5, 26.7);
      ctx.closePath();
      ctx.fill();
      ctx.stroke();
      ctx.restore();
    }
		function DrawDiffStriplineIcon(ctx) {
			// layer1/Path
      ctx.save();
      ctx.beginPath();
      ctx.moveTo(80.5, 45.4);
      ctx.lineTo(0.5, 45.4);
      ctx.lineTo(0.5, 4.2);
      ctx.lineTo(80.5, 4.2);
      ctx.lineTo(80.5, 45.4);
      ctx.closePath();
      ctx.fillStyle = "rgb(140, 198, 62)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(31.5, 26.7);
      ctx.lineTo(15.1, 26.7);
      ctx.lineTo(15.1, 22.9);
      ctx.lineTo(31.5, 22.9);
      ctx.lineTo(31.5, 26.7);
      ctx.closePath();
      ctx.fillStyle = "rgb(247, 147, 29)";
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(64.4, 26.7);
      ctx.lineTo(48.0, 26.7);
      ctx.lineTo(48.0, 22.9);
      ctx.lineTo(64.4, 22.9);
      ctx.lineTo(64.4, 26.7);
      ctx.closePath();
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(80.5, 49.1);
      ctx.lineTo(0.5, 49.1);
      ctx.lineTo(0.5, 45.4);
      ctx.lineTo(80.5, 45.4);
      ctx.lineTo(80.5, 49.1);
      ctx.closePath();
      ctx.fill();
      ctx.stroke();

      // layer1/Path
      ctx.beginPath();
      ctx.moveTo(80.5, 4.2);
      ctx.lineTo(0.5, 4.2);
      ctx.lineTo(0.5, 0.5);
      ctx.lineTo(80.5, 0.5);
      ctx.lineTo(80.5, 4.2);
      ctx.closePath();
      ctx.fill();
      ctx.stroke();
      ctx.restore();
    }
  </script>

<body onload="init()">

<table width="650" bgcolor = "#F0F0F0"> 
	<tr bgcolor = "#DCDCDC">
		<td onclick=SelectNew(1) width="25%" align="center" valign="bottom">
			<canvas id="canvas1" width="81" height="28"></canvas>
			<br>Microstrip
		</td>
		<td onclick=SelectNew(3) width="25%" align="center" valign="bottom">
			<canvas id="canvas3" width="81" height="28"></canvas>
			<br>Differential Microstrip
		</td>
		<td onclick=SelectNew(2) width="25%" align="center" valign="bottom">
			<canvas id="canvas2" width="81" height="28"></canvas>
			<br>Stripline
		</td>
		<td onclick=SelectNew(4) width="25%" align="center" valign="bottom">
			<canvas id="canvas4" width="81" height="50"></canvas>
			<br>Differential Stripline
		</td>
	</tr>
	<tr>
		<td valign="top" colspan = "4">
			<table width="100%">
				<tr><td>
					<table width="100%">
						<tr>
							<td align="center" width="80%"><canvas id="canvasGFX" width="181" height="84"></canvas></td>
							<td width="20%">
								<fieldset id="units">
									<legend>Units</legend>
									<input type="radio" name="units" value="Metric" checked="true" onchange=UnitChanged(0)>Metric<br>
									<input type="radio" name="units" value="Imperial" onchange=UnitChanged(1)>Imperial
								</fieldset>
							</td>
						</tr>
					</table>
				</td></tr>
				<tr>
					<td bgcolor = "#DCDCDC"><b>Inputs</b></td>
				</tr>
				<tr>
					<td>
						<form id="nothing" action="">
							<table>
								<tr>
									<td>Conductor Width (W)</td>								
									<td>W:</td><td><input type="text" id="valW" value = "0.254" onkeyup=calcul()></td><td id="unit1">mm</td>
								</tr>
								<tr id="SpacingRow" style="display: none;">
										<td>Conductor Spacing (S)</td>
										<td>S:</td><td><input type="text" id="valS" value = "0.127" onkeyup=calcul()></td><td id="unit2">mm</td>
									</tr>
								<tr>
									<td>Dielectric Thickness (H)</td>
									<td>H:</td><td><input type="text" id="valH" value = "0.381" onkeyup=calcul()></td><td id="unit3">mm</td>									
								</tr>
								<tr>
									<td>Copper Thickness (T)</td>
									<td>T:</td><td><input type="text" id="valT" value = "0.035" onkeyup=calcul()></td><td id="unit4">mm</td>
								</tr>
								<tr>
									<td>Relative Dielectric Constant (ER)</td>
									<td>ER:</td><td><input type="text" id="valER" value = "4.7" onkeyup=calcul()></td>
								</tr>
							</table>
						</form>
					</td>
				</tr>
				<tr>
					<td bgcolor = "#DCDCDC"><b>Outputs</b></td>
				</tr>
				<tr>
					<table width="100%" id="ResultHeader">
					</table>
					<table id="answer" width="100%">
					</table>
				</tr>			
			</table>  
		</td>
	</tr>
</table> 

